package com.moo2u2.android.oaktononthego.timesheet.dao;

import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.util.Log;

import com.moo2u2.android.oaktononthego.providers.TimesheetProvider;

public class TimesheetEntryTable {
	public static final String KEY_ROWID = "_id";

	public static final String KEY_TIMESHEET = "timesheet";

	public static final String KEY_DAY = "day";

	public static final String KEY_TYPE = "type";

	public static final String KEY_SUBTYPE = "subtype";

	public static final String KEY_HOURS = "hours";

	public static final String KEY_NOTES = "notes";

	public static final String ENTRY_TABLE = "timesheetentries";

	/**
	 * The content:// style URL for this table
	 */
	public static final Uri CONTENT_URI = Uri.parse("content://"
			+ TimesheetProvider.AUTHORITY + "/" + ENTRY_TABLE);

	/**
	 * The content URI base for a single row of data. Callers must append a
	 * numeric row id to this Uri to retrieve a row
	 */
	public static final Uri CONTENT_ID_URI_BASE = Uri.parse("content://"
			+ TimesheetProvider.AUTHORITY + "/entry/");

	private static final String ENTRY_CREATE = "create table " + ENTRY_TABLE
			+ "(" + KEY_ROWID + " integer primary key autoincrement, "
			+ KEY_TIMESHEET + " long not null, " + KEY_DAY + " int not null, "
			+ KEY_TYPE + " text not null, " + KEY_SUBTYPE + " text not null, "
			+ KEY_HOURS + ", " + KEY_NOTES + " text);";

	public static void onCreate(SQLiteDatabase database) {
		database.execSQL(ENTRY_CREATE);
	}

	public static void onUpgrade(SQLiteDatabase database, int oldVersion,
			int newVersion) {
		Log.w(TimesheetEntryTable.class.getName(),
				"Upgrading database from version " + oldVersion + " to "
						+ newVersion + ", which will destroy all old data");
		database.execSQL("DROP TABLE IF EXISTS " + ENTRY_TABLE);
		onCreate(database);
	}
}